import json
import os
import open3d as o3d
import numpy as np
from matplotlib import pyplot as plt
import random

# function ：ply to obj
def ply_to_obj(ply_path, obj_path):
    mesh = o3d.io.read_triangle_mesh(ply_path)
    o3d.io.write_triangle_mesh(obj_path, mesh)
    return mesh

def ply_to_stl(ply_path, stl_path):
    mesh = o3d.io.read_triangle_mesh(ply_path)
    o3d.io.write_triangle_mesh(stl_path, mesh)
    return mesh

# if __name__ == "__main__":
#     # 使用open3d可视化npy文件
#     # 读取npy文件
#     import numpy as np
#     import open3d as o3d
#     # np.set_printoptions(suppress=True) # 取消默认科学计数法，open3d无法读取科学计数法表示
#     # # 加载 .npy 文件中的点云数据
#     # point_cloud_np = np.load('3d/models_pcd_03.npy')[0]
#     # print(point_cloud_np.shape)
#     # np.savetxt('scene.txt', point_cloud_np[:,:3])

#     # # # 创建 Open3D 点云对象
#     # point_cloud_o3d = o3d.geometry.PointCloud()
#     # point_cloud_o3d.points = o3d.utility.Vector3dVector(point_cloud_np)

#     # # # 可视化点云
#     # o3d.visualization.draw_geometries([point_cloud_o3d])

#     folder=r'e:\pose\datasets\obj_ac\obj_000001\model\points.ply'
#     # # 使用open3d可视化ply文件
#     # # 读取ply文件
#     mesh = o3d.io.read_triangle_mesh(folder)
#     # # 可视化ply文件
#     o3d.visualization.draw_geometries([mesh])
    # 去除点云的颜色信息

if __name__ == "__main__":
    ply_path = r"E:\pose\datasets\obj_ac\obj_000000\model\model.ply"
    obj_path = ply_path.replace('.ply', '.obj')
    ply_to_obj(ply_path, obj_path)
    print('done')
    # 可视化obj
    mesh = o3d.io.read_triangle_mesh(obj_path)
    o3d.visualization.draw_geometries([mesh])

